"""The application's model objects"""
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base

from ajaxblog.model import meta
from datetime import datetime

def init_model(engine):
    """Call me before using any of the tables or classes in the model"""
    global Post
    sm = sessionmaker(autoflush=False, transactional=True, bind=engine)
    meta.engine = engine
    meta.Session = scoped_session(sm)
    
    Base = declarative_base(engine, mapper=meta.Session.mapper)
    class Post(Base):
        __tablename__ = 'posts'
        id = Column(Integer, primary_key=True)
        title = Column(String, nullable=False)
        body = Column(String, nullable=False)
        posted_at = Column(DateTime, nullable=False, default=datetime.now())
